package com.edu.app.service.impl.ai;

import com.edu.app.bean.core.SysCustomer;
import com.edu.app.bean.core.SysTenant;
import com.edu.app.bean.virtualbean.KeyValueItems;
import com.edu.app.bean.virtualbean.NameValueItems;
import com.edu.app.bean.virtualbean.UserActByDate;
import com.edu.app.bean.virtualbean.customize.PoCustomerStatus;
import com.edu.app.bean.virtualbean.customize.PoStudentStatus;
import com.edu.app.mapper.ai.SysAIMapper;
import com.edu.app.service.sys.ai.SysAIService;
import com.edu.app.threadlocal.TenantContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysAIServiceImpl implements SysAIService {
    @Autowired
    private SysAIMapper sysAIMapper;

    @Override
    public List<SysCustomer> getNotActiveCustomer(String username, Integer range){
        SysTenant curTenantId = (SysTenant) TenantContext.getCurrentTenant();
        List<SysCustomer> sysCustomerList = sysAIMapper.getNotActiveCustomer(username, range,curTenantId.getId());
        return sysCustomerList;
    }

    @Override
    public Integer getTeacherPendingConfirmNum(String username){
        return sysAIMapper.getTeacherPendingActivityNumber(username);
    }

    @Override
    public Integer getTeacherPendingFeedbackNumber(String username){
        return sysAIMapper.getTeacherPendingFeedbackNumber(username);
    }

    @Override
    public NameValueItems getTeacherLessonCompleteRank(String username){
        SysTenant curTenantId = (SysTenant)TenantContext.getCurrentTenant();
        return sysAIMapper.getTeacherLessonCompleteRank(username,curTenantId.getId());
    }

    @Override
    public List<UserActByDate> getUserActListByDateWithRole(String date, String role){
        return sysAIMapper.getUserActListByDateWithRole(date, role);
    }

    @Override
    public List<UserActByDate> getUserActListByDateWithRoleAndUser(String date, String role, String username, String actType){
        return sysAIMapper.getUserActListByDateWithRoleAndUser(date, role, username, actType);
    }

    @Override
    public List<NameValueItems> getTeacherCompleteLessonNumber(Integer number, Integer type, String date){
        switch(type){
            case 0:
                return sysAIMapper.getTeacherCompleteLessonNumberByDay(number, date);
            case 1:
                return sysAIMapper.getTeacherCompleteLessonNumberByWeek(number, date);
            case 2:
                return sysAIMapper.getTeacherCompleteLessonNumberByMonth(number, date);
            default:
                return sysAIMapper.getTeacherCompleteLessonNumberByDay(number, date);
        }
    }

    @Override
    public List<NameValueItems> getTeacherDemoLessonNumber(Integer number, Integer type, String date){
        switch(type){
            case 0:
                return sysAIMapper.getTeacherDemoLessonNumberByDay(number, date);
            case 1:
                return sysAIMapper.getTeacherDemoLessonNumberByWeek(number, date);
            case 2:
                return sysAIMapper.getTeacherDemoLessonNumberByMonth(number, date);
            default:
                return sysAIMapper.getTeacherDemoLessonNumberByDay(number, date);
        }
    }

    @Override
    public PageInfo getPoStudentStatus(Integer currentPage, Integer pageSize, Integer type){

        PageHelper.startPage(currentPage, pageSize, true);
        List<PoStudentStatus> list;

        switch(type){
            case 0:
                list = sysAIMapper.getPoStudentStatusToday();
                break;
            case 1:
                list = sysAIMapper.getPoStudentStatusFuture();
                break;
            case 2:
                list = sysAIMapper.getPoStudentStatusPast();
                break;
            case 3:
                list = sysAIMapper.getPoStudentStatusAll();
                break;
            default:
                list = sysAIMapper.getPoStudentStatusToday();
                break;
        }

        PageInfo<PoStudentStatus> pageInfo = new PageInfo<PoStudentStatus>(list);
        return pageInfo;


    }

    @Override
    public PageInfo getPoCustomerStatus(Integer currentPage, Integer pageSize, Integer type){

        PageHelper.startPage(currentPage, pageSize, true);
        List<PoCustomerStatus> list;

        switch(type){
            case 0:
                list = sysAIMapper.getPoCustomerStatusCompleteDemoClassAll();
                break;
            case 1:
                list = sysAIMapper.getPoCustomerStatusPendingDemoClassAll();
                break;
            default:
                list = sysAIMapper.getPoCustomerStatusCompleteDemoClassAll();
                break;
        }

        PageInfo<PoCustomerStatus> pageInfo = new PageInfo<PoCustomerStatus>(list);
        return pageInfo;


    }

    @Override
    public PageInfo getPoStudentStatusMine(Integer currentPage, Integer pageSize, String nickname){

        PageHelper.startPage(currentPage, pageSize, true);
        List<PoStudentStatus> list = sysAIMapper.getPoStudentStatusMine(nickname);

        PageInfo<PoStudentStatus> pageInfo = new PageInfo<PoStudentStatus>(list);
        return pageInfo;


    }

    @Override
    public List<KeyValueItems> getMarketingStatus(String dateYYMM){
        return sysAIMapper.getMarketingStatus(dateYYMM);
    }

    @Override
    public List<KeyValueItems> getDemoClassStatus(String dateYYMM){
        return sysAIMapper.getDemoClassStatus(dateYYMM);
    }

    @Override
    public List<KeyValueItems> getClassCompleteStatus(String dateYYMM){
        return sysAIMapper.getClassCompleteStatus(dateYYMM);
    }

    @Override
    public List<KeyValueItems> getMemberAgeRange(){
        return sysAIMapper.getMemberAgeRange();
    }

    @Override
    public Integer getPoCustomerStatusCompleteDemoClassAllNumber(){
        return  sysAIMapper.getPoCustomerStatusCompleteDemoClassAllNumber();
    }

    @Override
    public Integer getPoCustomerStatusPendingDemoClassAllNumber(){
        return  sysAIMapper.getPoCustomerStatusPendingDemoClassAllNumber();
    }

    @Override
    public PageInfo getPoCustomerByUser(Integer currentPage, Integer pageSize, String username, Integer type){

        PageHelper.startPage(currentPage, pageSize, true);
        List<PoCustomerStatus> list;

        switch(type){
            case 0:
                list = sysAIMapper.getPoCustomerNotStartByUser(username, "未开始");;
                break;
            case 1:
                list = sysAIMapper.getPoCustomerByUser(username, "工作中");
                break;
            case 2:
                list = sysAIMapper.getPoCustomerByUser(username, "已试听");
                break;
            case 3:
                list = sysAIMapper.getPoCustomerByUser(username, "第%次跟进");
                break;
            case 4:
                list = sysAIMapper.getPoCustomerByUser(username, "已成单");
                break;
            case 5:
                list = sysAIMapper.getPoCustomerByUser(username, "丢弃");
                break;
            default:
                list = sysAIMapper.getPoCustomerStatusCompleteDemoClassAll();
                break;
        }

        PageInfo<PoCustomerStatus> pageInfo = new PageInfo<PoCustomerStatus>(list);
        return pageInfo;


    }

    /*New APIs both for sales and teachers*/
    @Override
    public List<NameValueItems> getUserActivityTotalNumber(Integer status, String type, String date){
        return sysAIMapper.getUserActivityTotalNumber(status, type, date);
    }

    @Override
    public List<NameValueItems> getUserActivityNumber(Integer status, String type, String date){
        return sysAIMapper.getUserActivityNumber(status, type, date);
    }
}
